#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //禁止编辑
    ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->pushButton_2->setEnabled(false);

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(init()));

}

Widget::~Widget()
{
    delete ui;
}

void Widget::numcheck(int cnum, int max, int *buf)
{
    while(buf[cnum] == buf[cnum-1])
    {
        buf[cnum] = rand()%max + 1;
    }
}
void Widget::init()
{
    qsrand(time(NULL));
    int i=0;
       //产生5以内的随机数
    int  ss[6]={0};
    for (;i<6;i++) {
        ss[i]=qrand()%33+1;
        if(0!=i)
        {
         numcheck(i,33,ss);
        }
    }

    for (i=0;i<6;i++) {
        //qDebug()<<"红球》》"<<ss[i];
        QTableWidgetItem *item = new QTableWidgetItem;
                       item->setText(QString::number(ss[i]));
                       item->setFont(QFont("song", 34));
                       item->setForeground(QBrush(QColor(255,0,0)));
                       ui->tableWidget->setItem(0,i,item);
    }

    QTableWidgetItem *item = new QTableWidgetItem;
                   item->setText(QString::number(qrand()%16+1));
                   item->setFont(QFont("song", 34));
                   item->setForeground(QBrush(QColor(0,0,255)));
                   ui->tableWidget->setItem(0,6,item);
                   update();
}
void Widget::on_pushButton_clicked()
{
    ui->pushButton->setEnabled(false);
    ui->pushButton_2->setEnabled(true);
    timer->start(1000);
    this->init();
}

void Widget::on_pushButton_2_clicked()
{
    ui->pushButton->setEnabled(true);
    ui->pushButton_2->setEnabled(false);
    timer->stop();
}
